package org.flow.basic.io.file_io;

import java.io.*;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;

/**
 * @author xl-9527
 * @since 2025/2/21
 **/
public class NioFileTransfers {

    private static final int FILE_SIZE = 1024;

    /**
     * 传输 begin -> end
     *
     * @param begin 原始文件
     * @param end 拷贝以后的新文件
     */
    public void transfer(final File begin, final File end) {
        try (
                FileInputStream inputStream = new FileInputStream(begin);
                FileOutputStream outputStream = new FileOutputStream(end)
        ) {
            // get channel
            FileChannel inChannel = inputStream.getChannel();
            FileChannel outChannel = outputStream.getChannel();
            MappedByteBuffer mappedByteBuffer = inChannel.map(FileChannel.MapMode.READ_ONLY, 0, inChannel.size());
            System.out.println("读取完毕");
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
